package cn.zwxky.android.staff.HomePage;

import android.content.Intent;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.config.Config;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.DensityUtils;
import com.zgscwjm.lsfbbasetemplate.utils.SN;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.zwxky.android.staff.Approve.LeaveAdapter;
import cn.zwxky.android.staff.R;
import cn.zwxky.android.staff.Utils.LittleUtils;
import cn.zwxky.android.staff.Utils.URLString;

/**
 * Created by Administrator on 2017/3/29 0029.
 */
@ContentView(R.layout.aty_footprint)
public class FootprintActivity extends LsfbActivity {


    /**
     * 点击刷新布局控件
     */
    @ViewInject(R.id.swiplayout)
    private SwipeRefreshLayout swipeRefreshLayout;

    /**
     * list列表
     */
    @ViewInject(R.id.dish_list)
    private RecyclerView dish_list;

    /**
     * RecyclerView的布局管理器
     */
    private RecyclerView.LayoutManager mlayoutManager;

    private List<FootprintBean.ListBean> mList;

    private FootprintAdapter adapter;

    @Override
    public void initView() {
        LittleUtils.setsimpletitlebar(this, "足迹");
        TextView textView = new TextView(this);
        textView.setText("签到");
        textView.setTextColor(getResources().getColor(R.color.white_color));
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

             startActivity(new Intent(FootprintActivity.this,SignActivity.class));

            }
        });
        getTitleBar().setRightView(textView, 0, 0, DensityUtils.dp2px(this, 10), 0);

        mList=new ArrayList<>();
        adapter=new FootprintAdapter(this,mList,R.layout.item_footprint);
        mlayoutManager = new LinearLayoutManager(this);//布局模式为listview方式
        dish_list.setLayoutManager(mlayoutManager);
        dish_list.setAdapter(adapter);

        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                getData();
            }
        });
    }

    @Override
    public void initEvent() {

    }

    @Override
    public void initData() {
        getData();
    }

    public void getData(){
        HashMap<String, String> hashMap = new HashMap<String, String>();
             hashMap.put("uid", Config.getUserId());
        new BaseInternet().getData_Get(URLString.SIGNLIST, hashMap, FootprintBean.class, new FootprintEvent<FootprintBean>(), true,true);
    }

    @EventAnnotation
    public void FootprintEvent(FootprintEvent<FootprintBean> event){
        swipeRefreshLayout.setRefreshing(false);
        switch (event.getCode()){
            case 200:
                mList.clear();
                mList.addAll(event.getData().getList());
                adapter.notifyDataSetChanged();
                break;
            default:
                SN.SnackShow(dish_list,event.getMsg());
                break;
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }
}
